package org.duoyi.striver.consts;

import com.develop.jawin.COMException;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.duoyi.jdm.Dm.DmInstant;
import org.duoyi.striver.global.DmManager;
import org.duoyi.striver.model.impl.Sleeper;

/**
 * 快捷键
 */
@Slf4j
public enum Shortcuts {
    /** Alt+I */
    日程(18, 89),
    挂机界面(18, 78),
    Esc(27),
    打开背包(18, 69),
    任务面板(18, 81),
    ;

    private int[] keys;

    Shortcuts(@NonNull int... keys) {
        this.keys = keys;
    }

    public void press() {
        Sleeper.sleep();
//        log.info("准备按键【{}】", this.name());
        DmInstant dmInstant = DmManager.get();
        try {
            for (int key : this.keys) {
                dmInstant.KeyDown(key);
            }
            for (int key : this.keys) {
                dmInstant.KeyUp(key);
            }
            Sleeper.sleep();
        } catch (COMException e) {
            log.error("按键【{}】失败", this.name());
        }
    }
}
